


/**
 * 检查订单是否付款完成定时器
 * @type {null}
 */
paycheck_overtime_clock = null

$(function () {

    // 切换付款
    $(".buy-box-mask .buy-box .right .goods-select li").click(function()
    {
        if(!$(this).hasClass("active"))
        {
            that=this
            post("/api/member/pay/CreatePayOrder",{"id":$(this).find(".vip-goods_id").val()},function (response) {
                if(response.status == 1)
                {
                    //清空定时器
                    clearInterval(paycheck_overtime_clock);
                    //执行前端显示逻辑
                    $(".buy-box-mask .buy-box .right .goods-select li").removeClass("active")
                    $(that).addClass("active")
                    //修改显示的价格
                    $(".show-pay .pay-price").text($(that).find(".pay-price").text())
                    //修改支付宝付款链接
                    $(".pay-type-select .alipay a").attr("href","/alipay/pay.html?vip_goods_id="+$(that).find(".vip-goods_id").val())
                    //修改账户付款链接
                    // $(".pay-type-select .account a").attr("href","/page/member/alipaypay.html?vip_goods_id="+$(that).find(".vip-goods_id").val())
                    //修改微信付款码
                    $(".pay-type-select .wxpay .qrcode").children().remove()
                    $(".pay-type-select .wxpay .qrcode").qrcode({
                        render: "canvas",                    //设置渲染方式，有table和canvas，使用canvas方式渲染性能相对来说比较好
                        text: utf16to8(response.result.wx_qrcode),                       //扫描二维码后显示的内容,可以直接填一个网址，扫描二维码后自动跳向该链接
                        width: "100",                         //二维码的宽度
                        height: "100",                        //二维码的高度
                        background: "#ffffff",           //二维码的后景色
                        foreground: "#000000"       //二维码的前景色
                    });
                    //启动定时器
                    paycheck_overtime_clock = window.setInterval(function ()
                    {
                        post("/api/member/pay/CheckOrderStatus",{"order_sn":response.result.goodsOrder.sn},function (data)
                        {
                            if(data.status == 1)
                            {
                                CloseBuyBox();
                                //刷新页面
                                return alert("付款成功");
                            }
                        })

                    }, 1000)
                }else
                {
                    CloseBuyBox()
                    return alert(response.msg)
                }

            })

        }

    })

})

/**
 * 下载商品
 */
function downloadGoods(goods_id)
{

   post("/api/member/downloadGoods",
       {"goods_id":goods_id},
       function (response)
   {
       if(response.status == 1)
       {
           window.location.href = response.result;
       }else
           showBuyBox()
   })
}
/**
 * 显示购买弹框
 */
function showBuyBox()
{
    $(".box-mask").fadeOut();
    $(".buy-box-mask").fadeIn();
}
/**
 * 关闭购买弹框
 * @constructor
 */
function CloseBuyBox()
{
    //清空定时器
    clearInterval(paycheck_overtime_clock);
    //关闭弹框
    $(".buy-box-mask").fadeOut();
}